package com.example.b_308.myapplication.view.register;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.view.base.BaseFragment;
import com.example.b_308.myapplication.view.page.WorkPageAdapter;
import com.example.b_308.myapplication.view.page.WorkViewPage;
import com.example.b_308.myapplication.view.base.BaseActivity;
import com.example.b_308.myapplication.view.title.TitleBar;
import com.example.b_308.myapplication.view.user.LoginActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by B-308 on 2017/11/29.
 */
public class RegisterActivity extends BaseActivity implements View.OnClickListener{

    private TitleBar titleBar;
    WorkViewPage w_vp;
    RadioGroup rb;
    Button rb_info;
    int current=0;
    List<BaseFragment> fragments = new ArrayList<>();


    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        w_vp = (WorkViewPage) findViewById(R.id.w_vp2);
        rb =findId(R.id.rg_verification);
        rb_info =findId(R.id.rb_info);

        titleBar = (TitleBar) findViewById(R.id.title_bar);
        titleBar.setTitle("注册账号");
        titleBar.getIv_return().setOnClickListener(this);

        fragments.add(new RegisterFragment1());
        fragments.add(new RegisterFragment2());
        fragments.add(new RegisterFragment3());
        fragments.add(new RegisterFragment4());
        fragments.add(new RegisterFragment5());

        w_vp.setAdapter(new WorkPageAdapter(getSupportFragmentManager(), fragments));
        w_vp.setCurrentItem(current);
    }



    public<T> void next(BaseFragment fragment){
        if (current<5) {
            if(current==1){
                rb_info.setSelected(true);
            }
            if(current==3){
                rb.setSelected(true);
            }
            if(current==4){
                tentTo(LoginActivity.class);
            }
            current = current + 1;
        }
        w_vp.setCurrentItem(current);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_return:
                if (current>0){
                    current=current-1;
                    w_vp.setCurrentItem(current);
                }else {
                    tentTo(LoginActivity.class);
                }break;
        }
    }

}
